package com.vhall.component.dao.sign;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.vhall.component.entity.sign.SignRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 16964
 */
@Mapper
@Repository
public interface SignRecordMapper extends BaseMapper<SignRecord> {

    /**
     * 查询总数
     *
     * @param appId
     * @param roomId
     * @param signId
     * @return
     */
    @Select("<script>" +
            " select count(distinct(t.signer_id)) as count from sign_record t" +
            " <where>" +
            " <if test='signId!= null'>" +
            " and t.sign_id=#{signId}" +
            " </if>" +
            " and t.app_id=#{appId}" +
            " and t.room_id=#{roomId}" +
            " </where>" +
            " </script>")
    Integer distinctStat(@Param("appId") String appId, @Param("roomId") String roomId, @Param("signId") Long signId);

    /**
     * selectSignAfterLiveStart
     *
     * @param roomId
     * @param createdAt
     * @param offset
     * @param pageSize
     * @return
     */
    @Select("<script>" +
            " select signer_id as account_id from sign_record t" +
            " <where>" +
            "  t.room_id=#{roomId}" +
            " and created_at > #{createdAt}" +
            " limit #{offset},#{pageSize}" +
            " </where>" +
            " </script>")
    List<Integer> selectSignAfterLiveStart(@Param("roomId") String roomId, @Param("createdAt") String createdAt, @Param("offset") int offset, @Param("pageSize") int pageSize);

    /**
     * selectSignAfterLiveStartCount
     *
     * @param roomId    房间id
     * @param createdAt 创建时间
     * @return
     */
    @Select("<script>" +
            " select count(*) from sign_record t" +
            " <where>" +
            "  t.room_id=#{roomId}" +
            " and created_at > #{createdAt}" +
            " </where>" +
            " </script>")
    Integer selectSignAfterLiveStartCount(@Param("roomId") String roomId, @Param("createdAt") String createdAt);

}